import java.util.Arrays;

class Solution59 {
    public static void main(String[] args) {
        System.out.println(Arrays.deepToString(generateMatrix(3)));
    }
    public static int[][] generateMatrix(int n) {
         int[][] arr = new int[n][n] ; 
         int left = 0 ; 
         int right = n-1 ;
         int top = 0 ; 
         int botton = n-1 ;
         int ret = 1 ;
         while(ret <= n*n){
             for(int i=left ; i <= right ; i ++ , ret++){
                arr[top][i] = ret ; 
             }
             for(int j=top+1 ; j <=botton ; j ++ , ret++){
                arr[j][right] = ret ;
             }
             for(int i=right-1 ; i >= left && top!=botton ; i-- , ret++){
                 arr[botton][i] = ret ; 
             }
             for(int j=botton-1 ; j>top && left!=right ; j-- , ret++){
                arr[j][left] = ret ;
             }
             left ++ ;
             top ++ ;
             botton -- ;
             right -- ;
         }
         return arr ;

    }
}